package com.frxuexi.demo01_compose.view

import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ExperimentalLayoutApi
import androidx.compose.foundation.layout.FlowRow
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.foundation.lazy.grid.items
import androidx.compose.foundation.lazy.staggeredgrid.LazyHorizontalStaggeredGrid
import androidx.compose.foundation.lazy.staggeredgrid.LazyVerticalStaggeredGrid
import androidx.compose.foundation.lazy.staggeredgrid.StaggeredGridCells
import androidx.compose.foundation.lazy.staggeredgrid.items
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.CheckCircle
import androidx.compose.material3.Icon
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.DpSize
import androidx.compose.ui.unit.dp
import coil.compose.AsyncImage
import com.blankj.utilcode.util.ToastUtils
import com.frxuexi.demo01_compose.Message
import com.frxuexi.demo01_compose.R

@OptIn(ExperimentalLayoutApi::class)
@Preview
@Composable
fun MyPage(/*onClick: () -> Unit*/) {
    /*Box(contentAlignment= Alignment.BottomEnd) {
        Image(painter = painterResource(id = R.drawable.ic_launcher_background),
            contentDescription = "",
            modifier = Modifier.clip(CircleShape))
        Icon(imageVector = Icons.Default.CheckCircle, contentDescription = "",
            modifier = Modifier.padding(5.dp))
    }*/

    /*var modifier = Modifier
        .size(DpSize(100.dp, 30.dp)).background(Color.Cyan)
    Column {
        Text(text = "文本", modifier = modifier
            .clickable {*//*onClick()*//* })
        Text(
            text = "文本",
            modifier = modifier.offset(x = 10.dp)
        )
    }*/
    /*var modifier = Modifier.border(1.dp,Color.Black, shape = RoundedCornerShape(10.dp)).background(Color.Cyan, shape = RoundedCornerShape(10.dp)).padding(5.dp)
    FlowRow(Modifier.padding(5.dp),horizontalArrangement= Arrangement.spacedBy(10.dp),verticalArrangement=Arrangement.spacedBy(10.dp)){
        Text(text = "haha",modifier=modifier)
        Text(text = "hahasd",modifier=modifier)
        Text(text = "hahadscd",modifier=modifier)
        Text(text = "hahadscd",modifier=modifier)
        Text(text = "hahadscd",modifier=modifier)
        Text(text = "hahadscd",modifier=modifier)
    }*/



}

@Composable
fun MyGrid(list: MutableList<Message>){
    LazyVerticalGrid(modifier = Modifier.fillMaxSize(),verticalArrangement=Arrangement.spacedBy(10.dp),columns = GridCells.Adaptive(120.dp), content = {
        items(list){
            Column(verticalArrangement=Arrangement.spacedBy(10.dp),horizontalAlignment= Alignment.CenterHorizontally) {
                Image(painter = painterResource(id = it.img), contentDescription = "",
                    modifier = Modifier.height(100.dp))

                Text(text = it.title)
            }
        }
    })
}

@Composable
fun MyStaggeredGrid(){
    val list = mutableListOf<Message>()
    for (i in 1..20){
        list.add(Message(R.drawable.ic_launcher_background,"张三"+i,"描述内容"+i))
    }
    LazyVerticalStaggeredGrid(columns = StaggeredGridCells.Adaptive(120.dp),horizontalArrangement= Arrangement.spacedBy(10.dp), content = {
        items(list){
            Column(verticalArrangement=Arrangement.spacedBy(10.dp),horizontalAlignment= Alignment.CenterHorizontally) {
                Image(painter = painterResource(id = it.img), contentDescription = "",
                    modifier = Modifier.height(100.dp))

                Text(text = it.title)
            }
        }
    })
}

@Composable
fun MyImage(){
    AsyncImage(
        model = "https://img0.baidu.com/it/u=1033018635,7901815&fm=253&app=138&size=w931&n=0&f=JPEG&fmt=auto?sec=1719334800&t=144849ea92427b8edea7a1837e6ba584",
        contentDescription = null,
    )
}
